<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>设备维护>巡检>线缆测试</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <link
      rel="stylesheet"
      href="../../lib/layui-v2.5.5/css/layui.css"
      media="all"
    />
    <link rel="stylesheet" href="../../css/public.css" media="all" />
  </head>
  <style>
    .layui-table-grid-down {
      display: none;
    }
  </style>
  <body>
    <div class="layuimini-container">
      <div class="layuimini-main">
        <div id="Myloading">
          <img
            src="../../lib/layui-v2.5.5/css/modules/layer/default/loading-01.gif"
            alt=""
          />
        </div>
        <script type="text/html" id="toolbarDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add">
              新增
            </button>
          </div>
        </script>

        <table
          class="layui-hide"
          id="HcurrentTableId"
          lay-filter="currentTableFilter"
        ></table>

        <script type="text/html" id="currentTableBar">
          <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit"
            >查看</a
          >
          <a
            class="layui-btn layui-btn-xs data-count-edit layui-btn-danger"
            lay-event="delete"
            >删除</a
          >
        </script>
      </div>
    </div>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script
      src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"
      charset="utf-8"
    ></script>
    <script>
      layui.use(["table", "miniTab"], function () {
        // 2020-03-25 HF 保存token
        var token = sessionStorage.getItem("newtoken");
        var H_text = sessionStorage.getItem("HsaveOverHaul_text");
        var H_code = sessionStorage.getItem("HsaveOverHaul_code");
        var H_type = sessionStorage.getItem("HsaveOverHaul_type");

        var $ = layui.jquery,
          miniTab = layui.miniTab,
          table = layui.table;
        miniTab.listen();

        if (H_type == 5) {
          var url =
            "/oms-web/patrols/transformer/" +
            H_code +
            "/list/authority?token=" +
            token;
        } else if (H_type == 16) {
          var url =
            "/oms-web/patrols/GIS/" + H_code + "/list/authority?token=" + token;
        } else if (H_type == 12) {
          var url =
            "/oms-web/patrols/arrester/" +
            H_code +
            "/list/authority?token=" +
            token;
        }

        table.render({
          elem: "#HcurrentTableId",
          url: url,
          toolbar: "#toolbarDemo",
          parseData: function (res) {
            //res 即为原始返回的数据
            return {
              code: res.code, //解析接口状态
              msg: res.msg, //解析提示文本
              count: res.data.total, //解析数据长度
              data: res.data.list, //解析数据列表
            };
          },
          defaultToolbar: [
            "filter",
            "exports",
            "print",
            {
              title: "提示",
              layEvent: "LAYTABLE_TIPS",
              icon: "layui-icon-tips",
            },
          ],

          cols: [
            [
              //复选框 {type: "checkbox", width: 50, fixed: "left"},
              { type: "numbers", width: 200, title: "序号", align: "center" },
              {
                field: "patrolDate",
                minWidth: 200,
                title: "巡检时间",
                align: "center",
              },
              {
                field: "patrolStaff",
                minWidth: 200,
                title: "巡检人员",
                align: "center",
              },
              {
                title: "操作",
                width: 250,
                templet: "#currentTableBar",
                fixed: "right",
                align: "center",
              },
            ],
          ],
          limits: [10, 15, 20, 25, 50, 100],
          limit: 15,
          page: true,
          done: function (res) {
            if (res.code == -1) {
              window.location = "../login-1.html";
            }
            // 表格渲染完成回调
            $("#Myloading").remove();
          },
        });

        /**
         * toolbar监听事件
         */
        table.on("toolbar(currentTableFilter)", function (obj) {
          if (obj.event === "add") {
            // 监听添加操作
            if (H_text == "变压器") {
              layer.open({
                title: "新增变压器配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "./xun_jian.html",
              });
            } else if (H_text == "GIS") {
              layer.open({
                title: "新增GIS配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "./GIS_add.html",
              });
            } else if (H_text == "避雷器") {
              layer.open({
                title: "新增避雷器配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "./Arrester_add.html",
              });
            }
          }
        });

        //监听表格复选框选择
        table.on("checkbox(currentTableFilter)", function (obj) {
          console.log(obj);
        });

        // 获取列表data
        table.on("tool(currentTableFilter)", function (obj) {
          sessionStorage.setItem("HsaveOverHaul_recordNo", obj.data.recordNo);

          if (obj.event === "edit") {
            if (H_text == "变压器") {
              layer.open({
                title: "查看修改变压器配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "././line_x/see_xj.html",
              });
            } else if (H_text == "GIS") {
              layer.open({
                title: "查看修改GIS配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "./GIS_update.html",
              });
            } else if (H_text == "避雷器") {
              layer.open({
                title: "查看修改避雷器配置",
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ["100%", "100%"],
                content: "./Arrester_update.html",
              });
            }
          } else if (obj.event === "delete") {
            if (H_text == "变压器") {
              layer.confirm(
                "确定删除该数据吗？",
                {
                  btn: ["确定", "取消"], //按钮
                },
                function () {
                  $.ajax({
                    url:
                      "/oms-web/patrols/transformer/" +
                      obj.data.recordNo +
                      "/authority?token=" +
                      token,
                    dataType: "json",
                    type: "delete",
                    contentType: "application/json",
                    success: function (data) {
                      if (data.code == -1) {
                        window.location = "../login-1.html";
                      }
                      if (data.code === 0) {
                        layer.msg(
                          data.msg,
                          { icon: 1, time: 1000 },
                          function () {
                            window.location.reload(); //修改成功后刷新父界面
                          }
                        );
                      } else {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                      }
                    },
                    error: function () {
                      layer.msg("数据请求错误！");
                    },
                  });
                }
              );
            } else if (H_text == "GIS") {
              layer.confirm(
                "确定删除该数据吗？",
                {
                  btn: ["确定", "取消"], //按钮
                },
                function () {
                  $.ajax({
                    url:
                      "/oms-web/patrols/GIS/" +
                      obj.data.recordNo +
                      "/authority?token=" +
                      token,
                    dataType: "json",
                    type: "delete",
                    contentType: "application/json",
                    success: function (data) {
                      if (data.code == -1) {
                        window.location = "../login-1.html";
                      }
                      if (data.code === 0) {
                        layer.msg(
                          data.msg,
                          { icon: 1, time: 1000 },
                          function () {
                            window.location.reload(); //修改成功后刷新父界面
                          }
                        );
                      } else {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                      }
                    },
                    error: function () {
                      layer.msg("数据请求错误！");
                    },
                  });
                }
              );
            } else if (H_text == "避雷器") {
              layer.confirm(
                "确定删除该数据吗？",
                {
                  btn: ["确定", "取消"], //按钮
                },
                function () {
                  $.ajax({
                    url:
                      "/oms-web/patrols/arrester/" +
                      obj.data.recordNo +
                      "/authority?token=" +
                      token,
                    dataType: "json",
                    type: "delete",
                    contentType: "application/json",
                    success: function (data) {
                      if (data.code == -1) {
                        window.location = "../login-1.html";
                      }
                      if (data.code === 0) {
                        layer.msg(
                          data.msg,
                          { icon: 1, time: 1000 },
                          function () {
                            window.location.reload(); //修改成功后刷新父界面
                          }
                        );
                      } else {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                      }
                    },
                    error: function () {
                      layer.msg("数据请求错误！");
                    },
                  });
                }
              );
            }
          }
        });
      });
    </script>
  </body>
</html>
